﻿@{
    Layout = null;
    ViewData["Title"] = "IndexUdp";
}
<script src="~/js/vue.js"></script>
<script src="~/js/axios.js"></script>
<script src="~/element-ui/lib/index.js"></script>
<link rel="stylesheet" href="~/element-ui/lib/theme-chalk/index.css" />
<h1>IndexUdp职位发布变更</h1>
<div id="app">
    <el-table :data="tableData" stripe
              style="width: 100%">
        <el-table-column prop="major_name"
                         label="职位名称"
                         width="150">
        </el-table-column>
        <el-table-column prop="second_kind_name"
                         label="公司名称"
                         width="180">
        </el-table-column>
        <el-table-column prop="human_amount"
                         label="招聘人数"
                         width="100">
        </el-table-column>
        <el-table-column prop="regist_time"
                         label="发布时间"
                         width="180">
        </el-table-column>
        <el-table-column prop="deadline"
                         label="截止时间"
                         width="180">
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button size="mini"
                           v-on:click="handleEdit(scope.row)">编辑</el-button>
                <el-button size="mini"
                           type="danger"
                           v-on:click="handleDelete(scope.row.mre_id)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination v-on:size-change="handleSizeChange"
                   v-on:current-change="handleCurrentChange"
                   :current-page="pgcurrent"
                   :page-sizes="[3, 6, 9, 11]"
                   :page-size="pgsize"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="rows">
    </el-pagination>
    <el-dialog title="提示"
               :visible.sync="dialogVisibleUdp"
               width="100%">
        <el-form ref="form" :model="formData" label-width="80px">
            @*第一行*@
            <el-row>
                <el-col :span="6">
                    <el-form-item label="I级机构">
                        <el-select v-model="first_kind" placeholder="请选择" value-key="first_kind_id">
                            <el-option v-for="item in fks"
                                       :key="item.first_kind_id"
                                       :label="item.first_kind_name"
                                       :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="II级机构">
                        <el-select v-model="second_kind" placeholder="请选择" value-key="second_kind_id">
                            <el-option v-for="item in sks"
                                       :key="item.second_kind_id"
                                       :label="item.second_kind_name"
                                       :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="III级机构">
                        <el-select v-model="third_kind" placeholder="请选择" value-key="third_kind_id">
                            <el-option v-for="item in tks"
                                       :key="item.third_kind_id"
                                       :label="item.third_kind_name"
                                       :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="招聘类型">
                        <el-select v-model="engage_type" placeholder="请选择">
                            <el-option v-for="item in ets"
                                       :key="item.engage_type"
                                       :label="item.label"
                                       :value="item.engage_type">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            @*第二行*@
            <el-row>
                <el-col :span="6">
                    <el-form-item label="职位分类">
                        <el-cascader v-model="cmkValue"
                                     :options="cmks"
                                     :props="optionProps"
                                     v-on:change="handleChange" ref="cmkk"></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="招聘人数">
                        <el-input v-model="engagenum"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="截至日期">
                        <el-date-picker v-model="clsDate"
                                        type="datetime"
                                        placeholder="选择日期时间">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            @*第三行*@
            <el-row>
                <el-col :span="6">
                    <el-form-item label="登记人">
                        @Context.Session.GetString("uname")
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="变更时间">
                        <el-date-picker v-model="change_time"
                                        type="datetime"
                                        placeholder="选择日期时间" :disabled="true">
                        </el-date-picker>
                    </el-form-item>

                </el-col>
            </el-row>
            @*第四行*@
            <el-row>
                <el-col :span="18">
                    <el-form-item label="职位描述">
                        <el-input type="textarea"
                                  :rows="5"
                                  placeholder="请输入职业描述"
                                  v-model="major_describe">
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            @*第五行*@
            <el-row>
                <el-col :span="18">
                    <el-form-item label="招聘要求">
                        <el-input type="textarea"
                                  :rows="5"
                                  placeholder="请输入招聘要求"
                                  v-model="engage_required">
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item>
                <el-button v-on:click="dialogVisibleUdp = false">取 消</el-button>
                <el-button type="primary" v-on:click="JobRUpdate">确 定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</div>
<script type="text/javascript">
    var vue = new Vue({
        el: "#app",
        data: {
            //职位类型联级选择器数据源
            cmks: [],
            //选中项绑定值
            cmkValue: [],
            //次级菜单的展开方式和数据源绑定
            optionProps: {
                expandTrigger: 'hover',
                value: 'id',
                label: 'name',
                children: 'children'
            },
            tableData: [],
            pgcurrent: 1,
            pgsize: 3,
            rows: 0,
            //模态框
            dialogVisibleUdp: false,
            //I级机构
            fks: [],
            first_kind: {
                first_kind_id: '',
                first_kind_name: '',
            },
            //II级机构
            sks: [],
            second_kind: {
                second_kind_id: '',
                second_kind_name: '',
            },
            //III级机构
            tks: [],
            third_kind: {
                third_kind_id: '',
                third_kind_name: '',
            },
            //招聘类型下拉列表框
            ets: [{
                engage_type: '校园招聘',
                label: '校园招聘'
            }, {
                engage_type: '社会招聘',
                label: '社会招聘'
            }],
            engage_type: '',
            //招聘人数
            engagenum: '',
            //终止招聘时间
            clsDate: '',
            //变更招聘时间
            change_time: '',
            //职位描述
            major_describe: '',
            //招聘要求
            engage_required: '',
            //职位登记表主键
            mre_id: '',
        },
        methods: {
            emrfill() {
                axios.get('/JobRegist/EngageMajorReleaseFill?pgsize=' + this.pgsize + "&pgcurrent=" + this.pgcurrent).then((res) => {
                    this.rows = res.data.rows;
                    this.tableData = res.data.tabs;
                })
            },
            //编辑模态框中下拉列表框的源数据
            fstkinds() {
                axios.get("/ConfigFile/fstKindsFill").then(res => {
                    this.fks = res.data[0].tabs;
                    this.sks = res.data[1].tabs;
                    this.tks = res.data[2].tabs;
                });
                axios.get("/EngageResume/CMKCascader").then(res => {
                    console.info("res.data:", res.data);
                    this.cmks = res.data;
                });
            },
            //页面容量改变事件
            handleSizeChange(val) {
                this.pgsize = val;
                this.emrfill();
            },
            //页面下标改变事件
            handleCurrentChange(val) {
                this.pgcurrent = val;
                this.emrfill();
            },
            handleChange(val) {
                console.info("val:", val);
            },
            //修改事件
            handleEdit(row) {
                console.info("zheshixiugaide:", row);
                //将下拉列表框的值赋空
                this.first_kind = {};
                this.second_kind = {};
                this.third_kind = {};
                this.config_major_kind = {};
                this.config_public_char = {};
                this.engage_type = '';
                //打开修改模态框
                this.dialogVisibleUdp = true;
                this.mre_id = row.mre_id;
                this.first_kind.first_kind_id = row.first_kind_id;
                this.first_kind.first_kind_name = row.first_kind_name;
                this.second_kind.second_kind_id = row.second_kind_id;
                this.second_kind.second_kind_name = row.second_kind_name;
                this.third_kind.third_kind_id = row.third_kind_id;
                this.third_kind.third_kind_name = row.third_kind_name;
                this.engage_type = row.engage_type;
                //联级选择器键和值回显
                this.cmkValue = [parseInt(row.major_kind_id.trim()), parseInt(row.major_id.trim())];

                this.engagenum = row.human_amount;
                this.clsDate = row.deadline;
                this.major_describe = row.major_describe;
                this.engage_required = row.engage_required;
            },
            JobRUpdate() {
                //console.info(this.first_kind, "this.first_kind.first_kind_id:",
                //    this.first_kind.first_kind_id, this.first_kind.first_kind_name,
                //    this.second_kind.second_kind_id, this.second_kind.second_kind_name,
                //    this.third_kind.third_kind_id, this.third_kind.third_kind_name,
                //    this.cmkValue[0].toString(), this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[0],
                //    this.cmkValue[1].toString(), this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[1],
                //    this.engagenum, this.clsDate, this.engage_type, this.change_time, this.major_describe, this.engage_required,
                //);
                axios.post("/JobRegist/EngageMajorReleaseUpdate", {
                    mre_id: this.mre_id,
                    first_kind_id: this.first_kind.first_kind_id,
                    first_kind_name: this.first_kind.first_kind_name,
                    second_kind_id: this.second_kind.second_kind_id,
                    second_kind_name: this.second_kind.second_kind_name,
                    third_kind_id: this.third_kind.third_kind_id,
                    third_kind_name: this.third_kind.third_kind_name,

                    major_kind_id:this.cmkValue[0].toString(),
                    major_kind_name: this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[0],
                    major_id:this.cmkValue[1].toString(),
                    major_name: this.$refs['cmkk'].getCheckedNodes()[0].pathLabels[1],

                    human_amount: this.engagenum,
                    deadline: this.clsDate,
                    engage_type: this.engage_type,
                    change_time: this.change_time,
                    major_describe: this.major_describe,
                    engage_required: this.engage_required,
                }).then(res => {
                    if (res.data > 0) {
                        this.opensuc('修改');
                        //调用刷新方法
                        this.emrfill();
                        this.dialogVisibleUdp = false;
                    }
                });
            },
            //删除事件
            handleDelete(mre_id) {
                console.info(mre_id);
                this.$confirm('确定要和删除这条招聘信息吗？', "温馨提示：").then(() => {
                    axios.delete('/JobRegist/EngageMajorReleaseDelete?mre_id=' + mre_id).then(res => {
                        if (res.data > 0) {
                            this.opensuc('删除');
                            //调用刷新方法
                            this.emrfill();
                        }
                    });
                }).catch(err => {
                    console.info("已取消删除招聘信息！");
                })

            },
            //操作成功弹窗
            opensuc(msg) {
                this.$message({
                    message: '恭喜您，' + msg + '招聘信息成功！',
                    type: 'success'
                });
            },
            //获取当前时间
            getNowTime() {
                var now = new Date();
                var year = now.getFullYear(); //获取年
                var month = now.getMonth();//获取月
                var date = now.getDate();//获取日
                var hours = now.getHours();//获取小时
                var minutes = now.getMinutes();//获取分钟
                var seconds = now.getSeconds();//获取秒
                month = month + 1;
                month = month.toString().padStart(2, "0");
                date = date.toString().padStart(2, "0");
                var defaultDate = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
                this.change_time = new Date();
            },
            //定义时间戳
            created() {
                setInterval(() => {
                    this.getNowTime();
                }, 500);
            },
        },
        mounted: function() {
            this.emrfill();
            this.fstkinds();
            this.created();
        }
    })
</script>
